package cn.psvmc.cxzapi.response;


import cn.psvmc.cxzapi.enums.ResultCode;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;

import java.io.Serializable;

/**
 * 统一API响应结果封装
 */
public class Result<T> implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 3913566023103012448L;

    @JSONField(ordinal = 1)
    private int code;

    @JSONField(ordinal = 2)
    private String msg;

    @JSONField(ordinal = 3)
    private T obj;

    public Result<T> setCode(ResultCode resultCode) {
        this.code = resultCode.getCode();
        return this;
    }

    public int getCode() {
        return code;
    }

    public Result<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getObj() {
        return obj;
    }

    public Result<T> setObj(T obj) {
        this.obj = obj;
        return this;
    }

    public Result(T obj) {
        super();
        this.obj = obj;
    }

    public Result() {
        super();
        this.obj = null;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
